(function() {
  "use strict";
  APP.Views.AppMenuView = Backbone.View.extend({
    tagName: 'ul',
    events : {
      'click a': 'remove',
      'click .hideAction': 'hideApp',
      'click .showPrersonalizeViewAction': 'showPrersonalizeView'
    },
    initialize: function(params) {
      this.appId = params.appId;
      this.appView = params.appView;
      this.menuView = params.menuView;
      this.$el.addClass('dropdown-menu displayBlock');
      this.$el.attr('role', 'menu');
      this.$el.css({
        top: params.coord.y,
        left: params.coord.x
      })
    },
    hideApp: function(e) {
      e.preventDefault();
      APP.BeClient.hideApp(this.appId, null, null, {preloaderShow: false, preloaderHide: false});
      this.remove();
      var self = this;
      this.appView.$el.fadeOut(300, function() {
        self.appView.remove();
        self.menuView.tiles[self.appId] = undefined
        $('#menuBase').masonry('reload');
      });
    },
    showPrersonalizeView: function(e) {
      e.preventDefault();
      new APP.Views.DialogPersonalizeView({
        appId: this.appId,
        appView: this.appView
      });
    },
    render: function() {
      this.$el.html(_.template($('#appMenuTemplate').html(), {}));
      return this;
    }
  });
}());